package com.dhcc.DRGsHosp.facade.impl;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Serializable;
import java.io.StringReader;
import java.io.Writer;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Stack;
import java.util.UUID;
import java.util.regex.Pattern;

import javax.inject.Named;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.openkoala.koala.commons.InvokeResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

import com.dhcc.DRGsHosp.application.CostSubApplication;
import com.dhcc.DRGsHosp.application.DepGroupApplication;
import com.dhcc.DRGsHosp.application.DepartmentApplication;
import com.dhcc.DRGsHosp.application.MedicalRecordApplication;
import com.dhcc.DRGsHosp.core.domain.CostSub;
import com.dhcc.DRGsHosp.core.domain.DepGroup;
import com.dhcc.DRGsHosp.core.domain.Department;
import com.dhcc.DRGsHosp.core.domain.MedicalRecord;
import com.dhcc.DRGsHosp.facade.MedicalRecordNewFacade;
import com.dhcc.DRGsHosp.infra.util.ConstantEnum;
import com.dhcc.DRGsHosp.infra.util.Properties;
import com.dhcc.DRGsHosp.infra.util.StringUtils;

/**
 * @title		:MedicalRecordFacadeNewImpl.java
 * @description	:
 * @author		:WangTeng
 * @date		:2016年6月1日
 * @version     :1.0
 * @copyright   :DHCC 2013-2014 
 */
@Named("drgsHospFacadeImpl30")
public class MedicalRecordFacadeNewImpl implements MedicalRecordNewFacade,Serializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private static final String propertiesPath = MedicalRecordFacadeNewImpl.class.getResource("/medicalrecord-mapping.properties").getFile();
	
	private List<MedicalRecord> mrList = new ArrayList<MedicalRecord>();
//	private List<Operation> operList = new ArrayList<Operation>();
//	private List<Diagnosis> diagList = new ArrayList<Diagnosis>();
	//private List<Cost> costList = new ArrayList<Cost>();
	
	Map<String, String> depCodeMap = new HashMap<String, String>();//科室名称代码信息
	Map<String, String> hisDepCodeMap = new HashMap<String, String>();//科室名称代码信息
	Map<String, String> hisDepNameMap = new HashMap<String, String>();//HIS科室名称对照信息
	Map<String, String> wardDepNameMap = new HashMap<String, String>();//病区科室名称对照信息
	Map<String, String> costCodeMap = new HashMap<String, String>();//费用名称代码信息
	
	@Autowired
	private MedicalRecordApplication medicalRecordApplication;
	
//	@Autowired
//	private OperationApplication operationApplication;
	
	//@Autowired
//	private DiagnosisApplication diagnosisApplication;
	
	
	@Autowired
	private CostSubApplication costSubApplication;
	
	@Autowired
	private DepartmentApplication  departmentApplication;

	@Autowired
	private DepGroupApplication  depGroupApplication;
	
	
	private static Map<String, String> tagDescMap = new HashMap<String, String>();
	private static Map<String, String> feeDescMap = new HashMap<String, String>();
	static{
		tagDescMap.put("adm_No", "adm号");
		tagDescMap.put("patient_name", "姓名");
		tagDescMap.put("hosp_inf", "院感信息");
		tagDescMap.put("gender", "性别");
		tagDescMap.put("date_of_birth", "出生日期");
		tagDescMap.put("age", "年龄");
		tagDescMap.put("newborns_weight", "新生儿入院体重");
		tagDescMap.put("newborns_days", "新生儿住院天数");
		tagDescMap.put("marital_status", "婚姻状况代码");
		tagDescMap.put("payment_way", "医疗付费方式代码");
		tagDescMap.put("health_card_No", "医疗保险手册(卡)号(健康卡号)");
		tagDescMap.put("medical_record_No", "病案号");
		tagDescMap.put("times_of_hospitalizations", "住院次数");
		tagDescMap.put("in_date", "入院日期");
		tagDescMap.put("in_time", "入院时间（时）");
		tagDescMap.put("in_dep", "入院科别");
		tagDescMap.put("his_in_dep", "HIS入院科别");
		tagDescMap.put("in_ward", "入院病房");
		tagDescMap.put("in_way", "入院途径");
		tagDescMap.put("out_date", "出院日期");
		tagDescMap.put("out_time", "出院时间（时）");
		tagDescMap.put("out_dep", "出院科别");
		tagDescMap.put("his_out_dep", "HIS出院科别");
		tagDescMap.put("out_ward", "出院病房");
		tagDescMap.put("in_days", "实际住院天数");
		tagDescMap.put("transfer_dep", "转经科别");
		tagDescMap.put("door_diagnosis_code", "门(急)诊诊断编码");
		tagDescMap.put("door_diagnosis_name", "门（急）诊诊断名称");
		tagDescMap.put("main_diagnosis_code", "主要诊断编码");
		tagDescMap.put("main_diagnosis_name", "主要诊断名称");
		tagDescMap.put("diagnosis_code", "诊断编码");
		tagDescMap.put("diagnosis_name", "诊断名称");
		tagDescMap.put("diagnosis_type_code", "诊断类型");
		
		tagDescMap.put("main_diagnosis_type_code", "主要诊断类型代码");
		tagDescMap.put("door_diagnosis_type_code", "门(急)诊诊断类型代码");
		tagDescMap.put("other_diagnosis_type_code", "其他诊断类型代码");
		
		tagDescMap.put("in_condition", "入院病情");
		tagDescMap.put("pathological_diagnosis_code", "病理诊断编码");
		tagDescMap.put("pathological_diagnosis_name", "病理诊断名称");
		tagDescMap.put("pathological_No", "病理号");
		tagDescMap.put("operation_start_time", "手术开始时间");
		tagDescMap.put("operation_end_time", "手术结束时间");
		tagDescMap.put("operation_doctor", "术者");
		tagDescMap.put("assistant_one", "Ⅰ助姓名");
		tagDescMap.put("assistant_two", "Ⅱ助姓名");
		tagDescMap.put("anesthesia_code", "麻醉方式代码");
		tagDescMap.put("cut_level", "切口愈合等级代码");
		tagDescMap.put("anesthesiologists", "麻醉医师姓名");
		tagDescMap.put("operation_level", "手术级别代码");
		tagDescMap.put("operation_code", "手术及操作编码");
		tagDescMap.put("operation_name", "手术及操作名称");
		tagDescMap.put("operation_type_code", "手术或操作代码");
		
		tagDescMap.put("surg_code", "手术代码");
		tagDescMap.put("oper_code", "操作代码");
		
		tagDescMap.put("is_main_operation", "是否主要手术或操作");
		tagDescMap.put("have_drug_allergy", "有无药物过敏");
		tagDescMap.put("medical_record_quality", "病案质量代码");
		tagDescMap.put("QC_physician_name", "质控医师姓名");
		tagDescMap.put("QC_nurse_name", "质控护士姓名");
		tagDescMap.put("dep_director_name", "科主任姓名");
		tagDescMap.put("director_doctor_name", "主(副主)任医师姓名");
		tagDescMap.put("physician_name", "主治医师姓名");
		tagDescMap.put("resident_name", "住院医师姓名");
		tagDescMap.put("physician_learn_name", "进修医师姓名");
		tagDescMap.put("intern_name", "实习医师姓名");
		tagDescMap.put("nurses_name", "责任护士姓名");
		tagDescMap.put("clinic_name", "主诊医师(组)");
		tagDescMap.put("coder_name", "编码员");
		tagDescMap.put("ventilator_hours", "呼吸机使用时间(小时)");
		tagDescMap.put("birth_weight", "新生儿出生体重(克)");
		tagDescMap.put("out_way", "离院方式代码");
		tagDescMap.put("turn_name", "医嘱转院、转社区、卫生院机构名称");
		tagDescMap.put("rescue_success", "是否抢救成功");
		tagDescMap.put("rescue_number", "抢救次数");
		tagDescMap.put("rescue_success_number", "抢救成功次数");
		tagDescMap.put("plan_31days", "是否有出院31日内再住院计划");
		tagDescMap.put("complications", "手术并发症");
		
		tagDescMap.put("total_fee", "总费用");
		tagDescMap.put("self_fee", "自付金额");
//		tagDescMap.put("fee1", "诊察（诊疗）费");
//		tagDescMap.put("fee2", "一般检查费");
//		tagDescMap.put("fee3", "临床物理治疗费");
//		tagDescMap.put("fee4", "介入治疗费");
//		tagDescMap.put("fee5", "特殊治疗费");
//		tagDescMap.put("fee6", "康复治疗费");
//		tagDescMap.put("fee7", "中医治疗费");
//		tagDescMap.put("fee8", "一般治疗费");
//		tagDescMap.put("fee9", "精神治疗费");
//		tagDescMap.put("fee10", "接生费");
//		tagDescMap.put("fee11", "麻醉费");
//		tagDescMap.put("fee12", "手术费");
//		tagDescMap.put("fee13", "护理治疗费");
//		tagDescMap.put("fee14", "护理费");
//		tagDescMap.put("fee15", "核素检查");
//		tagDescMap.put("fee16", "核素治疗");
//		tagDescMap.put("fee17", "超声费");
//		tagDescMap.put("fee18", "放射费");
//		tagDescMap.put("fee19", "化验费");
//		tagDescMap.put("fee20", "病理费");
//		tagDescMap.put("fee21", "监护及辅助呼吸费");
//		tagDescMap.put("fee22", "治疗用一次性医用材料费");
//		tagDescMap.put("fee23", "介入用一次性医用材料费");
//		tagDescMap.put("fee24", "手术用一次性医用材料费");
//		tagDescMap.put("fee25", "检查用一次性医用材料费");
//		tagDescMap.put("fee26", "床位费");
//		tagDescMap.put("fee27", "挂号费");
//		tagDescMap.put("fee28", "输氧费");
//		tagDescMap.put("fee29", "输血费");
//		tagDescMap.put("fee30", "西药费");
//		tagDescMap.put("fee31", "抗菌药物费");
//		tagDescMap.put("fee32", "白蛋白类制品费");
//		tagDescMap.put("fee33", "球蛋白类制品费");
//		tagDescMap.put("fee34", "凝血因子类制品费");
//		tagDescMap.put("fee35", "细胞因子类制品费");
//		tagDescMap.put("fee36", "中成药费");
//		tagDescMap.put("fee37", "中草药费");
//		tagDescMap.put("fee38", "其他费用");
		tagDescMap.put("patient", "病例节点");
		tagDescMap.put("operation", "手术节点");
		tagDescMap.put("diagnosis", "诊断节点");
		tagDescMap.put("cost", "费用节点");
	}

	@Override
	public InvokeResult generateProperties(Map<String, String> propMap) {
		
		Properties prop = new Properties();
		
		InputStream propInputStream = null;
		OutputStream propOutputStream = null;
		Writer writer = null;
		try {
			propInputStream = new FileInputStream(new File(propertiesPath));
			prop.load(propInputStream);
			
			for (String key : propMap.keySet()) {
				prop.setProperty(key, propMap.get(key));
			}
			
			//生成配置文件和注释
			propOutputStream = new FileOutputStream(new File(propertiesPath));
			writer = new OutputStreamWriter(propOutputStream);
			prop.store(writer,"\n MedicalRecord-Mapping properties file was generated by system in "+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
			//prop.store(propOutputStream, "\n         ____   /\\   ____\n        /   |  /  \\  |   \\\n       /   /  /    \\  \\   \\\n      /   /  /  /\\  \\  \\   \\\n      |  |__|  |__|  |__|  |\n      |  ___ WANGTENG ___  |\n      \\  \\  |  |  |  |  /  /\n       \\  \\ |  |  |  | /  /\n        \\  \\|  |  |  |/  /\n         \\_____|__|_____/\n\n MedicalRecord-Mapping properties file was generated by system in "+sdf.format(new Date()));
		} catch (IOException e) {
			e.printStackTrace();
			return InvokeResult.failure("properties生成失败！"+e.getMessage());
		} finally{
			try {
				propInputStream.close();
				propOutputStream.close();
				writer.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return InvokeResult.success("Properties生成成功！");
	}
	
	
	
	@Override
	public InvokeResult parseXmlTag(String xml) {
		List<Map<String, String>> propMapList = new ArrayList<Map<String,String>>();
		// step 1: 获得SAX解析器工厂实例
        SAXParserFactory factory = SAXParserFactory.newInstance();
        try {
	        // step 2: 获得SAX解析器实例
	        SAXParser parser = factory.newSAXParser();
	        // step 3: 开始进行解析
	        StringReader read = new StringReader(xml);
	        InputSource source = new InputSource(read);
	        
	        parser.parse(source, new ParseXmlHandler(propMapList));
        } catch (Exception e) {
			e.printStackTrace();
			InvokeResult.failure("xml解析失败！"+e.getMessage());
		}
        
		return InvokeResult.success(propMapList);
	}
	
	private class ParseXmlHandler extends DefaultHandler {
		
		List<String> tagNameList = new ArrayList<String>();	
		List<Map<String, String>> propMapList = new ArrayList<Map<String,String>>();
		
		public ParseXmlHandler(List<Map<String, String>> propMapList) {
			this.propMapList = propMapList;
		}
		
		// 使用栈这个数据结构来保存
	    private Stack<String> stack = new Stack<String>();
	    
	    @Override
	    public void startDocument() throws SAXException
	    {
	        System.out.println("start document -> parse begin");
	    }

	    @Override
	    public void endDocument() throws SAXException
	    {

	        System.out.println("end document -> parse finished");
	    }

	    @Override
	    public void startElement(String uri, String localName, String qName,
	            Attributes attributes) throws SAXException
	    {
	        // 将标签名压入栈
	        stack.push(qName);
	        if (!tagNameList.contains(qName)) {
				tagNameList.add(qName);
			}
	    }

	    @Override
	    public void characters(char[] ch, int start, int length)
	            throws SAXException
	    {
	        // 取出标签名
	    	String tagName = stack.peek();
	    	String tagValue = new String(ch, start, length);
	        Map<String, String> propMap = new HashMap<String, String>();
	        if (Pattern.matches("[Aa][Dd][Mm].*", tagValue.toLowerCase()) || Pattern.matches("adm_No", tagValue)) {
				//adm号
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "adm号");
				propMap.put("tagName", "adm_No");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches("姓名", tagValue) || Pattern.matches("patient_name", tagValue)) {
				//姓名
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "姓名");
				propMap.put("tagName", "patient_name");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches("院感.*", tagValue) || Pattern.matches("patient_name", tagValue)) {
				//姓名
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "院感信息");
				propMap.put("tagName", "hosp_inf");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches("性别([编代]码)*", tagValue) || Pattern.matches("[男女]", tagValue)) {
				//性别
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "性别");
				propMap.put("tagName", "gender");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches("出生日期", tagValue) || Pattern.matches("date_of_birth", tagValue)) {
				//出生日期
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "出生日期");
				propMap.put("tagName", "date_of_birth");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches("年龄.*", tagValue) || Pattern.matches("age", tagValue)) {
				//年龄
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "年龄");
				propMap.put("tagName", "age");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches("新生儿.*入院.*体重", tagValue) || Pattern.matches("newborns_weight", tagValue)) {
				//新生儿入院体重
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "新生儿入院体重");
				propMap.put("tagName", "newborns_weight");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			}  else if (Pattern.matches("新生儿.*天数", tagValue) || Pattern.matches("newborns_days", tagValue)) {
				//新生儿入院体重
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "新生儿住院天数");
				propMap.put("tagName", "newborns_days");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches("婚姻.+", tagValue) || Pattern.matches("marital_status", tagValue)) {
				//婚姻状况代码
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "婚姻状况代码");
				propMap.put("tagName", "marital_status");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches("(医疗)?付费方式[编代]码.*", tagValue) || Pattern.matches("payment_way", tagValue)) {
				//医疗付费方式代码
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "医疗付费方式代码");
				propMap.put("tagName", "payment_way");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches("(医疗保险)?(手册)?(健康)?卡号", tagValue) || Pattern.matches("health_card_No", tagValue)) {
				//医疗保险手册(卡)号(健康卡号)
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "医疗保险手册(卡)号(健康卡号)");
				propMap.put("tagName", "health_card_No");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches("病案号", tagValue) || Pattern.matches("medical_record_No", tagValue)) {
				//病案号
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "病案号");
				propMap.put("tagName", "medical_record_No");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches("住院次数", tagValue) || Pattern.matches("times_of_hospitalizations", tagValue)) {
				//住院次数
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "住院次数");
				propMap.put("tagName", "times_of_hospitalizations");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
				
			} else if (Pattern.matches("入院日期.*", tagValue) || Pattern.matches("in_date", tagValue)) {
				//入院日期
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "入院日期");
				propMap.put("tagName", "in_date");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches("入院时间.*", tagValue) || Pattern.matches("in_time", tagValue)) {
				//入院时间（时）
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "入院时间");
				propMap.put("tagName", "in_time");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches("入院科[别室](名称)*", tagValue) || Pattern.matches("in_dep", tagValue)) {
				//入院科别代码
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "入院科别");
				propMap.put("tagName", "in_dep");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches("([Hh][Ii][Ss])入院科[别室](名称)*", tagValue) || Pattern.matches("in_dep", tagValue)) {
				//入院科别代码
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "HIS入院科别");
				propMap.put("tagName", "his_in_dep");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches("入院病房(名称)*", tagValue) || Pattern.matches("in_ward", tagValue)) {
				//入院病房
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "入院病房");
				propMap.put("tagName", "in_ward");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches("入院途径([编代]码)?", tagValue) || Pattern.matches("in_way", tagValue)) {
				//入院途径
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "入院途径");
				propMap.put("tagName", "in_way");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches("出院日期.*", tagValue) || Pattern.matches("out_date", tagValue)) {
				//出院日期
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "出院日期");
				propMap.put("tagName", "out_date");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches("出院时间.*", tagValue) || Pattern.matches("out_time", tagValue)) {
				//出院时间（时）
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "出院时间（时）");
				propMap.put("tagName", "out_time");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches("出院科[别室](名称)*", tagValue) || Pattern.matches("out_dep", tagValue)) {
				//出院科别代码
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "出院科别");
				propMap.put("tagName", "out_dep");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches("([Hh][Ii][Ss])出院科[别室](名称)*", tagValue) || Pattern.matches("out_dep", tagValue)) {
				//出院科别代码
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "HIS出院科别");
				propMap.put("tagName", "his_out_dep");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches("([Hh][Ii][Ss])*出院病房(名称)*", tagValue) || Pattern.matches("out_ward", tagValue)) {
				//出院病房
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "出院病房");
				propMap.put("tagName", "out_ward");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches("(实际)?住院.*天.*", tagValue) || Pattern.matches("in_days", tagValue)) {
				//实际住院
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "实际住院天数");
				propMap.put("tagName", "in_days");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches("([Hh][Ii][Ss])*转(经)?科+[室别](名称)*(列表)?", tagValue) || Pattern.matches("transfer_dep", tagValue)) {
				//转经科别代码
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "转经科别");
				propMap.put("tagName", "transfer_dep");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches("门.*(急)?.*诊诊断[编代]码", tagValue) || Pattern.matches("door_diagnosis_code", tagValue)) {
				//门(急)诊诊断编码
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "门(急)诊诊断编码");
				propMap.put("tagName", "door_diagnosis_code");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches("门.*(急)?.*诊诊断名称", tagValue) || Pattern.matches("door_diagnosis_name", tagValue)) {
				//门（急）诊诊断名称
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "门（急）诊诊断名称");
				propMap.put("tagName", "door_diagnosis_name");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*主要诊断[编代]码.*", tagValue) || Pattern.matches("main_diagnosis_code", tagValue)) {
				//出院时主要诊断编码
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "出院时主要诊断编码");
				propMap.put("tagName", "main_diagnosis_code");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*主要诊断(名称)?.*", tagValue) || Pattern.matches("main_diagnosis_name", tagValue)) {
				//出院主要诊断名称
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "出院主要诊断名称");
				propMap.put("tagName", "main_diagnosis_name");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*(其[他它])?诊断[编代]码.*", tagValue) || Pattern.matches("diagnosis_code", tagValue)) {
				//出院时其他诊断编码
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "出院时其他诊断编码");
				propMap.put("tagName", "diagnosis_code");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*(其[他它])?诊断(名称)?.*", tagValue) || Pattern.matches("diagnosis_name", tagValue)) {
				//出院其他诊断名称
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "出院其他诊断名称");
				propMap.put("tagName", "diagnosis_name");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*诊断类型([编代]码)?", tagValue) || Pattern.matches("diagnosis_type_code", tagValue)) {
				//入院病情
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "诊断类型");
				propMap.put("tagName", "diagnosis_type_code");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches("入院.*情([编代]码)?", tagValue) || Pattern.matches("in_condition", tagValue)) {
				//入院病情
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "入院病情");
				propMap.put("tagName", "in_condition");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*病理诊断[编代]码", tagValue) || Pattern.matches("pathological_diagnosis_code", tagValue)) {
				//病理诊断编码
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "病理诊断编码");
				propMap.put("tagName", "pathological_diagnosis_code");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*病理诊断(名称)?", tagValue) || Pattern.matches("pathological_diagnosis_name", tagValue)) {
				//病理诊断名称
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "病理诊断名称");
				propMap.put("tagName", "pathological_diagnosis_name");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches("病理号", tagValue) || Pattern.matches("pathological_No", tagValue)) {
				//病理号
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "病理号");
				propMap.put("tagName", "pathological_No");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*手术.*开始.*", tagValue) || Pattern.matches("operation_start_time", tagValue)) {
				//手术开始时间
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "手术开始时间");
				propMap.put("tagName", "operation_start_time");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*手术.*结束.*", tagValue) || Pattern.matches("operation_end_time", tagValue)) {
				//手术结束时间
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "手术结束时间");
				propMap.put("tagName", "operation_end_time");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*术者.*", tagValue) || Pattern.matches("operation_doctor", tagValue)) {
				//术者
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "术者");
				propMap.put("tagName", "operation_doctor");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches("[1一Ⅰ]助(姓名)?", tagValue) || Pattern.matches("assistant_one", tagValue)) {
				//Ⅰ助姓名
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "Ⅰ助姓名");
				propMap.put("tagName", "assistant_one");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches("[2二Ⅱ]助(姓名)?", tagValue) || Pattern.matches("assistant_two", tagValue)) {
				//Ⅱ助姓名
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "Ⅱ助姓名");
				propMap.put("tagName", "assistant_two");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches("麻醉方式[编代]码", tagValue) || Pattern.matches("anesthesia_code", tagValue)) {
				//麻醉方式代码
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "麻醉方式代码");
				propMap.put("tagName", "anesthesia_code");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches("切口愈合.*[编代]码", tagValue) || Pattern.matches("cut_level", tagValue)) {
				//切口愈合等级代码
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "切口愈合等级代码");
				propMap.put("tagName", "cut_level");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches("麻醉医[师生](姓名)?", tagValue) || Pattern.matches("anesthesiologists", tagValue)) {
				//麻醉医师姓名
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "麻醉医师姓名");
				propMap.put("tagName", "anesthesiologists");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches("手术级别[编代]码", tagValue) || Pattern.matches("operation_level", tagValue)) {
				//手术级别代码
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "手术级别代码");
				propMap.put("tagName", "operation_level");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches("手术(及操作)?[编代]码.*", tagValue) || Pattern.matches("operation_code", tagValue)) {
				//手术及操作编码
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "手术及操作编码");
				propMap.put("tagName", "operation_code");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches("手术(及操作)?(名称)?", tagValue) || Pattern.matches("operation_name", tagValue)) {
				//手术及操作名称
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "手术及操作名称");
				propMap.put("tagName", "operation_name");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches("是否主要手术.*", tagValue) || Pattern.matches("is_main_operation", tagValue)) {
				//是否主要手术或操作
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "是否主要手术或操作");
				propMap.put("tagName", "is_main_operation");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*药物过敏", tagValue) || Pattern.matches("have_drug_allergy", tagValue)) {
				//有无药物过敏
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "有无药物过敏");
				propMap.put("tagName", "have_drug_allergy");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches("病案质量[编代]码", tagValue) || Pattern.matches("medical_record_quality", tagValue)) {
				//病案质量代码
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "病案质量代码");
				propMap.put("tagName", "medical_record_quality");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches("质控医[师生].*", tagValue) || Pattern.matches("QC_physician_name", tagValue)) {
				//质控医师姓名
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "质控医师姓名");
				propMap.put("tagName", "QC_physician_name");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches("质控护士.*", tagValue) || Pattern.matches("QC_nurse_name", tagValue)) {
				//质控护士姓名
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "质控护士姓名");
				propMap.put("tagName", "QC_nurse_name");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches("科(室)?主任.*", tagValue) || Pattern.matches("dep_director_name", tagValue)) {
				//科主任姓名
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "科主任姓名");
				propMap.put("tagName", "dep_director_name");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches("主.*任.*医[师生](姓名)?", tagValue) || Pattern.matches("director_doctor_name", tagValue)) {
				//主(副主)任医师姓名
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "主(副主)任医师姓名");
				propMap.put("tagName", "director_doctor_name");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches("主治医[师生](姓名)?", tagValue) || Pattern.matches("physician_name", tagValue)) {
				//主治医师姓名
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "主治医师姓名");
				propMap.put("tagName", "physician_name");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches("住院医[师生](姓名)?", tagValue) || Pattern.matches("resident_name", tagValue)) {
				//住院医师姓名
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "住院医师姓名");
				propMap.put("tagName", "resident_name");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches("进修医[师生](姓名)?", tagValue) || Pattern.matches("physician_learn_name", tagValue)) {
				//进修医师姓名
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "进修医师姓名");
				propMap.put("tagName", "physician_learn_name");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches("实习医[师生](姓名)?", tagValue) || Pattern.matches("intern_name", tagValue)) {
				//实习医师姓名
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "实习医师姓名");
				propMap.put("tagName", "intern_name");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*护士(姓名)?", tagValue) || Pattern.matches("nurses_name", tagValue)) {
				//责任护士姓名
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "责任护士姓名");
				propMap.put("tagName", "nurses_name");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches("主诊(医[师生])?(组)?", tagValue) || Pattern.matches("clinic_name", tagValue)) {
				//责任护士姓名
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "主诊医师");
				propMap.put("tagName", "clinic_name");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			}else if (Pattern.matches(".*编码员(姓名)?", tagValue) || Pattern.matches("coder_name", tagValue)) {
				//责任护士姓名
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "编码员");
				propMap.put("tagName", "coder_name");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches("呼吸机使用时间.*", tagValue) || Pattern.matches("ventilator_hours", tagValue)) {
				//呼吸机使用时间(小时)
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "呼吸机使用时间(小时)");
				propMap.put("tagName", "ventilator_hours");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches("新生儿(出生)?体重.*", tagValue) || Pattern.matches("birth_weight", tagValue)) {
				//新生儿出生体重(克)
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "新生儿出生体重(克)");
				propMap.put("tagName", "birth_weight");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches("离院方式[编代]码", tagValue) || Pattern.matches("out_way", tagValue)) {
				//离院方式代码
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "离院方式代码");
				propMap.put("tagName", "out_way");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches("医嘱转院.*(名称)?", tagValue) || Pattern.matches("turn_name", tagValue)) {
				//医嘱转院、转社区、卫生院机构名称
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "医嘱转院、转社区、卫生院机构名称");
				propMap.put("tagName", "turn_name");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches("是否.*抢救.*成功.*", tagValue) || Pattern.matches("rescue_success", tagValue)) {
				
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "是否抢救成功");
				propMap.put("tagName", "rescue_success");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches("抢救次数", tagValue) || Pattern.matches("rescue_number", tagValue)) {
				
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "抢救次数");
				propMap.put("tagName", "rescue_number");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches("抢救成功次数.*", tagValue) || Pattern.matches("rescue_success_number", tagValue)) {
				
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "抢救成功次数");
				propMap.put("tagName", "rescue_success_number");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*出院31.*计划", tagValue) || Pattern.matches("plan_31days", tagValue)) {
				//是否有出院31日内再住院计划
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "是否有出院31日内再住院计划");
				propMap.put("tagName", "plan_31days");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*并发症", tagValue) || Pattern.matches("complications", tagValue)) {
				//是否有出院31日内再住院计划
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "手术并发症");
				propMap.put("tagName", "complications");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*总费用", tagValue) || Pattern.matches("total_fee", tagValue)) {
				//总费用
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "总费用");
				propMap.put("tagName", "total_fee");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*自付.*", tagValue) || Pattern.matches("self_fee", tagValue)) {
				//自付金额
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "自付金额");
				propMap.put("tagName", "self_fee");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*诊察.*(诊疗)?.*费", tagValue) || Pattern.matches("fee1", tagValue)) {
				//诊察（诊疗）费
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "诊察（诊疗）费");
				propMap.put("tagName", "fee1");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*一般检查费", tagValue) || Pattern.matches("fee2", tagValue)) {
				//一般检查费
				System.out.println(tagValue+",,,"+tagName);
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "一般检查费");
				propMap.put("tagName", "fee2");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*临床物理治疗费", tagValue) || Pattern.matches("fee3", tagValue)) {
				//临床物理治疗费
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "临床物理治疗费");
				propMap.put("tagName", "fee3");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*介入治疗费", tagValue) || Pattern.matches("fee4", tagValue)) {
				//介入治疗费
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "介入治疗费");
				propMap.put("tagName", "fee4");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*特殊治疗费", tagValue) || Pattern.matches("fee5", tagValue)) {
				//特殊治疗费
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "特殊治疗费");
				propMap.put("tagName", "fee5");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*康复(治疗)?费", tagValue) || Pattern.matches("fee6", tagValue)) {
				//康复治疗费
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "康复治疗费");
				propMap.put("tagName", "fee6");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*中医治疗费", tagValue) || Pattern.matches("fee7", tagValue)) {
				//中医治疗费
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "中医治疗费");
				propMap.put("tagName", "fee7");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*一般治疗.*费", tagValue) || Pattern.matches("fee8", tagValue)) {
				//一般治疗费
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "一般治疗费");
				propMap.put("tagName", "fee8");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*精神治疗费", tagValue) || Pattern.matches("fee9", tagValue)) {
				//精神治疗费
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "精神治疗费");
				propMap.put("tagName", "fee9");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*接生费", tagValue) || Pattern.matches("fee10", tagValue)) {
				//接生费
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "接生费");
				propMap.put("tagName", "fee10");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*麻醉费", tagValue) || Pattern.matches("fee11", tagValue)) {
				//麻醉费
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "麻醉费");
				propMap.put("tagName", "fee11");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*手术费", tagValue) || Pattern.matches("fee12", tagValue)) {
				//手术费
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "手术费");
				propMap.put("tagName", "fee12");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*护理治疗费", tagValue) || Pattern.matches("fee13", tagValue)) {
				//护理治疗费
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "护理治疗费");
				propMap.put("tagName", "fee13");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*护理费", tagValue) || Pattern.matches("fee14", tagValue)) {
				//护理费
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "护理费");
				propMap.put("tagName", "fee14");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*核素检查(费)?", tagValue) || Pattern.matches("fee15", tagValue)) {
				//核素检查
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "核素检查");
				propMap.put("tagName", "fee15");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*核素治疗(费)?", tagValue) || Pattern.matches("fee16", tagValue)) {
				//核素治疗
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "核素治疗");
				propMap.put("tagName", "fee16");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*超声费", tagValue) || Pattern.matches("fee17", tagValue)) {
				//超声费
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "超声费");
				propMap.put("tagName", "fee17");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*放射费", tagValue) || Pattern.matches("fee18", tagValue)) {
				//放射费
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "放射费");
				propMap.put("tagName", "fee18");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*化验费", tagValue) || Pattern.matches("fee19", tagValue)) {
				//化验费
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "化验费");
				propMap.put("tagName", "fee19");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*病理费", tagValue) || Pattern.matches("fee20", tagValue)) {
				//病理费
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "病理费");
				propMap.put("tagName", "fee20");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*监护及辅助呼吸费", tagValue) || Pattern.matches("fee21", tagValue)) {
				//监护及辅助呼吸费
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "监护及辅助呼吸费");
				propMap.put("tagName", "fee21");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*治疗用一次性医用材料费", tagValue) || Pattern.matches("fee22", tagValue)) {
				//治疗用一次性医用材料费
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "治疗用一次性医用材料费");
				propMap.put("tagName", "fee22");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*介入用一次性医用材料费", tagValue) || Pattern.matches("fee23", tagValue)) {
				//介入用一次性医用材料费
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "介入用一次性医用材料费");
				propMap.put("tagName", "fee23");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*手术用一次性医用材料费", tagValue) || Pattern.matches("fee24", tagValue)) {
				//手术用一次性医用材料费
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "手术用一次性医用材料费");
				propMap.put("tagName", "fee24");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*检查用一次性医用材料费", tagValue) || Pattern.matches("fee25", tagValue)) {
				//检查用一次性医用材料费
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "检查用一次性医用材料费");
				propMap.put("tagName", "fee25");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*床位费", tagValue) || Pattern.matches("fee26", tagValue)) {
				//床位费
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "床位费");
				propMap.put("tagName", "fee26");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*挂号费", tagValue) || Pattern.matches("fee27", tagValue)) {
				//挂号费
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "挂号费");
				propMap.put("tagName", "fee27");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*输氧费", tagValue) || Pattern.matches("fee28", tagValue)) {
				//输氧费
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "输氧费");
				propMap.put("tagName", "fee28");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*血费", tagValue) || Pattern.matches("fee29", tagValue)) {
				//输血费
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "输血费");
				propMap.put("tagName", "fee29");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*西药费", tagValue) || Pattern.matches("fee30", tagValue)) {
				//西药费
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "西药费");
				propMap.put("tagName", "fee30");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*抗菌药物费", tagValue) || Pattern.matches("fee31", tagValue)) {
				//抗菌药物费
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "抗菌药物费");
				propMap.put("tagName", "fee31");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*白蛋白类制品费", tagValue) || Pattern.matches("fee32", tagValue)) {
				//白蛋白类制品费
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "白蛋白类制品费");
				propMap.put("tagName", "fee32");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*球蛋白类制品费", tagValue) || Pattern.matches("fee33", tagValue)) {
				//球蛋白类制品费
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "球蛋白类制品费");
				propMap.put("tagName", "fee33");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*凝血因子类制品费", tagValue) || Pattern.matches("fee34", tagValue)) {
				//凝血因子类制品费
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "凝血因子类制品费");
				propMap.put("tagName", "fee34");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*细胞因子类制品费", tagValue) || Pattern.matches("fee35", tagValue)) {
				//细胞因子类制品费
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "细胞因子类制品费");
				propMap.put("tagName", "fee35");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*中成药费", tagValue) || Pattern.matches("fee36", tagValue)) {
				//中成药费
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "中成药费");
				propMap.put("tagName", "fee36");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*中草药费", tagValue) || Pattern.matches("fee37", tagValue)) {
				//中草药费
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "中草药费");
				propMap.put("tagName", "fee37");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			} else if (Pattern.matches(".*其[他它]费(用)?", tagValue) || Pattern.matches("fee38", tagValue)) {
				//其他费用
				propMap = new HashMap<String, String>();
				propMap.put("tagDesc", "其他费用");
				propMap.put("tagName", "fee38");
				propMap.put("tagNameNew", tagName);
				if (!tagNameList.contains(propMap.get("tagName"))) {
					tagNameList.add(propMap.get("tagName"));
					propMapList.add(propMap);
				}
			}

	    }

	    @Override
	    public void endElement(String uri, String localName, String qName)
	            throws SAXException
	    {
	        stack.pop();// 表示该元素解析完毕，需要从栈中弹出标签
	    }
	}
	
	public static void main(String[] args) {
		
	}



	/* (non-Javadoc)
	 * @see com.dhcc.DRGsHosp.facade.MedicalRecordNewFacade#showMedicalrecordMapping()
	 */
	@Override
	public InvokeResult showMedicalrecordMapping() {
		Properties prop = new Properties();
		List<Map<String, String>> propList = new ArrayList<Map<String,String>>();
		Map<String, String> map = new HashMap<String, String>();
		InputStream propInputStream = null;
		try {
			propInputStream = new FileInputStream(new File(MedicalRecordFacadeNewImpl.class.getResource("/medicalrecord-mapping.properties").getFile()));
			prop.load(propInputStream);
			
//			Enumeration<Object> keys = prop.;
//			while (keys.hasMoreElements()) {
//				String key = keys.nextElement()+"";
//				map = new HashMap<String, String>();
//				map.put("tagDesc", tagDescMap.get(key));
//				map.put("tagName", key);
//				map.put("tagNameNew", prop.getProperty(key));
//				propList.add(map);
//			}
			
			List<CostSub> costsubList = costSubApplication.findAllCostSub();
			for (CostSub costSub : costsubList) {
				tagDescMap.put("fee"+costSub.getCostSubcode(), costSub.getCostSubdesc());
				feeDescMap.put("fee"+costSub.getCostSubcode(), costSub.getCostSubdesc());
			}
			
			for (String key : prop.getKeyList()) {
				if (key.length()>=1 && !"#".equals(key.substring(0,1))) {
					map = new HashMap<String, String>();
					map.put("tagDesc", tagDescMap.get(key));
					map.put("tagName", key);
					map.put("tagNameNew", prop.getProperty(key));
					propList.add(map);
				}
			}
			if(propList.size() <= 82){
				for (Map.Entry<String, String> entry:feeDescMap.entrySet()) {
						map = new HashMap<String, String>();
						map.put("tagDesc", entry.getValue());
						map.put("tagName", entry.getKey());
						map.put("tagNameNew", "");
						propList.add(map);
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
			return InvokeResult.failure(e.getMessage());
		} finally{
			try {
				propInputStream.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return InvokeResult.success(propList);
	}



	/* (non-Javadoc)
	 * @see com.dhcc.DRGsHosp.facade.MedicalRecordNewFacade#universalMedicalrecordImport(java.lang.String)
	 */
	@Override
	public String universalMedicalrecordImport(String xmlStr) {
		System.out.println("2. Enter interface implement class!");
		mrList = new ArrayList<MedicalRecord>();
	//	operList = new ArrayList<Operation>();
	//	diagList = new ArrayList<Diagnosis>();
	//	costList = new ArrayList<Cost>();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		
		//所有科室
		List<Department> depList = departmentApplication.findAllDepartment();
		Map<String, String> tempMap = new HashMap<String, String>();
		
		System.out.println("3. Got all departments ");
		for (Department dep : depList) {
			if (dep.getDepName()!=null) {
				depCodeMap.put(dep.getDepName(), dep.getDepCode());
			}
			System.out.println(dep.getDepName());
			if (dep.getDepHis()!=null) {
				String[] depHis = dep.getDepHis().split(",");
				for (String hisName : depHis) {
					System.out.println("  [hisDep]:"+hisName);
					hisDepCodeMap.put(hisName, dep.getDepCode());
					hisDepNameMap.put(hisName, dep.getDepName());
				}
			}
			tempMap.put(dep.getDepName(), dep.getDepWard());
		}
		
		for (String depName : tempMap.keySet()) {
			if (!StringUtils.isEmpty(tempMap.get(depName))) {
				String[] wards = tempMap.get(depName).split(",");
				for (String ward : wards) {
					wardDepNameMap.put(ward, depName);
				}
			}
		}
		
		List<CostSub> costsubList = costSubApplication.findAllCostSub();
		for (CostSub costSub : costsubList) {
			costCodeMap.put(costSub.getCostSubdesc(), costSub.getCostSubcode());
		}
		
		if (xmlStr!=null) {
			BufferedWriter bout = null;
			try {
				bout = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(ConstantEnum.DATAPATH+"/medicalrecordImport.txt"),"utf-8"));
	
				bout.write("-------------------------------------------------------------------------");
			    bout.newLine();
				bout.write("at "+sdf.format(new Date())+" 开始导入首页信息...");
			    bout.newLine();
				bout.write("at "+sdf.format(new Date())+" 开始解析xml...");
		        bout.newLine();
		        //bout.write(xmlStr);
		        System.out.println("4. Parse xmlStr start ...");
		        //解析xml=======================================================
				parseMedicalrecord(xmlStr);
				//==============================================================
				System.out.println("5. Parse xmlStr complete !");
				
				bout.write("at "+sdf.format(new Date())+" 解析完毕!");
			    bout.newLine();
			    bout.write("at "+sdf.format(new Date())+" 开始保存...");
			    bout.newLine();
				try {
					System.out.println("6. Save data start ...");
					//保存数据====================================================
					saveData();
					//===========================================================
					System.out.println("7. Save data complete ! ");
					//bout.write("at "+sdf.format(new Date())+" 保存成功！mrList:"+mrList.size()+",operList:"+operList.size()+",diagList:"+diagList.size()+",costList:"+costList.size());
				    bout.newLine();
				} catch (Exception e) {
					bout.write("at "+sdf.format(new Date())+" 保存失败："+e.toString());
			        bout.newLine();
			        e.printStackTrace();
				}
			} catch (Exception e) {
				try {
					bout.write("at "+sdf.format(new Date())+" 解析失败："+e.toString());
					bout.newLine();
				} catch (IOException e1) {
					e1.printStackTrace();
				}
				e.printStackTrace();
			}finally{
				try {
					bout.flush();
					bout.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		} else {
			return "<Response>"
					+ "<STATUS>导入失败</STATUS>"
					+ "<MESSAGE>xml is null</MESSAGE>"
				+ "</Response>";
		}
/*		return "<Response>"
					+ "<STATUS>导入成功</STATUS>"
					+ "<MESSAGE>首页数据:"+mrList.size()+"条，诊断数据："+diagList.size()+"条，手术数据："+operList.size()+"条，费用数据："+costList.size()+"条。</MESSAGE>"
				+ "</Response>";*/
		return null;
	}
	
	/**
	 * @methodname    :saveData
	 * @description   :保存首页、手术、诊断、费用数据
	 * @param         :
	 * @author        :WangTeng
	 * @return        :
	 * @date          :2016年6月6日
	 */
	private void saveData(){
		//保存
		for (MedicalRecord medicalRecord : mrList) {
		//	diagnosisApplication.removeDiagnosisByParid(medicalRecord.getId());
		//	operationApplication.removeOperationByParid(medicalRecord.getId());
		//	costApplication.removeCostByParid(medicalRecord.getId());
			medicalRecordApplication.creatMedicalRecord(medicalRecord);
		}
	/*	for (Operation operation : operList) {
			operationApplication.creatOperation(operation);
		}
		for (Diagnosis diagnosis : diagList) {
			diagnosisApplication.creatDiagnosis(diagnosis);
		}*/
	/*	for (Cost cost : costList) {
			//costApplication.creatCost(cost);
			costApplication.insertCost(cost);
		}*/
		//System.out.println("导入首页数据:"+mrList.size()+"条，诊断数据："+diagList.size()+"条，手术数据："+operList.size()+"条，费用数据："+costList.size()+"条。");
	}

	/**
	 * @methodname    :xmlParse
	 * @description   :SAX解析xml主过程
	 * @param         :
	 * @author        :lileizheng
	 * @return        :null
	 * @date          :2016年1月14日
	 */
	private void parseMedicalrecord(String xmlString) throws Exception{
		// step 1: 获得SAX解析器工厂实例
        SAXParserFactory factory = SAXParserFactory.newInstance();
        // step 2: 获得SAX解析器实例
        SAXParser parser = factory.newSAXParser();
        // step 3: 开始进行解析
        StringReader read = new StringReader(xmlString);  
        InputSource source = new InputSource(read);
        
        //加载properties配置
		InputStream propInputStream = new FileInputStream(new File(propertiesPath));
		java.util.Properties properties = new java.util.Properties();
		try {
			properties.load(propInputStream);
		} catch (IOException e) {
			e.printStackTrace();
		}
		
        parser.parse(source, new MedicalrecordParseHandler(properties));
	}
	
	
	/**
	 * @title		:OrderFacadeImpl.java
	 * @description	:SAX解析xml辅助类
	 * @author		:lileizheng
	 * @date		:2016年1月14日
	 * @version     :1.0
	 * @copyright   :DHCC 2013-2014
	 */
	private class MedicalrecordParseHandler extends DefaultHandler
	{
		public MedicalrecordParseHandler(java.util.Properties properties) {
			this.properties = properties;
		}
		
		private java.util.Properties properties = new java.util.Properties();
		// 使用栈这个数据结构来保存
	    private Stack<String> stack = new Stack<String>();
	    
	    Map<String, String> costMap = new HashMap<String, String>();
	    
	    double drugFee = 0;//药品费用
	    double materialFee = 0;//材料费用
	    
	    int surg_index = 1;//手术序号
	    int oper_index = 1;//操作序号
	    
	    // 数据
	    //adm号
	    private String adm_No;
	    private String adm_No_TAGNAME;

	    //姓名
	    private String patient_name;
	    private String patient_name_TAGNAME;

	    //姓名
	    private String hosp_inf;
	    private String hosp_inf_TAGNAME;

	    //性别
	    private String gender;
	    private String gender_TAGNAME;

	    //出生日期
	    private String date_of_birth;
	    private String date_of_birth_TAGNAME;

	    //年龄
	    private String age;
	    private String age_TAGNAME;

	    //新生儿入院体重
	    private String newborns_weight;
	    private String newborns_weight_TAGNAME;
	    
	    //新生儿住院天数
	    private String newborns_days;
	    private String newborns_days_TAGNAME;

	    //婚姻状况代码
	    private String marital_status;
	    private String marital_status_TAGNAME;

	    //医疗付费方式代码
	    private String payment_way;
	    private String payment_way_TAGNAME;

	    //医疗保险手册(卡)号(健康卡号)
	    private String health_card_No;
	    private String health_card_No_TAGNAME;

	    //病案号
	    private String medical_record_No;
	    private String medical_record_No_TAGNAME;

	    //住院次数
	    private String times_of_hospitalizations;
	    private String times_of_hospitalizations_TAGNAME;

	    				
	    //入院日期
	    private String in_date;
	    private String in_date_TAGNAME;

	    //入院时间（时）
	    private String in_time;
	    private String in_time_TAGNAME;

	    //入院科别代码
	    private String in_dep;
	    private String in_dep_TAGNAME;
	    
	    //HIS入院科别代码
	    private String his_in_dep;
	    private String his_in_dep_TAGNAME;

	    //入院病房
	    private String in_ward;
	    private String in_ward_TAGNAME;

	    //入院途径
	    private String in_way;
	    private String in_way_TAGNAME;

	    //出院日期
	    private String out_date;
	    private String out_date_TAGNAME;

	    //出院时间（时）
	    private String out_time;
	    private String out_time_TAGNAME;

	    //出院科别代码
	    private String out_dep;
	    private String out_dep_TAGNAME;
	    
	    //出院科别代码
	    private String his_out_dep;
	    private String his_out_dep_TAGNAME;

	    //出院病房
	    private String out_ward;
	    private String out_ward_TAGNAME;

	    //实际住院
	    private String in_days;
	    private String in_days_TAGNAME;

	    //转经科别代码
	    private String transfer_dep;
	    private String transfer_dep_TAGNAME;

	    //门(急)诊诊断编码
	    private String door_diagnosis_code;
	    private String door_diagnosis_code_TAGNAME;

	    //门（急）诊诊断名称
	    private String door_diagnosis_name;
	    private String door_diagnosis_name_TAGNAME;
	    
	    //出院时主要诊断类型代码
	    private String main_diagnosis_type_code;
	    //出院时其他诊断类型代码
	    private String other_diagnosis_type_code;
	    //门(急)诊诊断类型代码
	    private String door_diagnosis_type_code;

	    //出院时主要诊断编码
	    private String main_diagnosis_code;
	    private String main_diagnosis_code_TAGNAME;

	    //出院主要诊断名称
	    private String main_diagnosis_name;
	    private String main_diagnosis_name_TAGNAME;

	    //出院时其他诊断编码
	    private String diagnosis_code;
	    private String diagnosis_code_TAGNAME;

	    //出院其他诊断名称
	    private String diagnosis_name;
	    private String diagnosis_name_TAGNAME;
	    
	    //诊断类型
	    private String diagnosis_type_code;
	    private String diagnosis_type_code_TAGNAME;

	    //入院病情
	    private String in_condition;
	    private String in_condition_TAGNAME;

	    //病理诊断编码
	    private String pathological_diagnosis_code;
	    private String pathological_diagnosis_code_TAGNAME;

	    //病理诊断名称
	    private String pathological_diagnosis_name;
	    private String pathological_diagnosis_name_TAGNAME;

	    //病理号
	    private String pathological_No;
	    private String pathological_No_TAGNAME;

	    //手术开始时间
	    private String operation_start_time;
	    private String operation_start_time_TAGNAME;

	    //手术结束时间
	    private String operation_end_time;
	    private String operation_end_time_TAGNAME;

	    //术者
	    private String operation_doctor;
	    private String operation_doctor_TAGNAME;

	    //Ⅰ助姓名
	    private String assistant_one;
	    private String assistant_one_TAGNAME;

	    //Ⅱ助姓名
	    private String assistant_two;
	    private String assistant_two_TAGNAME;

	    //麻醉方式代码
	    private String anesthesia_code;
	    private String anesthesia_code_TAGNAME;

	    //切口愈合等级代码
	    private String cut_level;
	    private String cut_level_TAGNAME;

	    //麻醉医师姓名
	    private String anesthesiologists;
	    private String anesthesiologists_TAGNAME;

	    //手术级别代码
	    private String operation_level;
	    private String operation_level_TAGNAME;

	    //手术及操作编码
	    private String operation_code;
	    private String operation_code_TAGNAME;

	    //手术及操作名称
	    private String operation_name;
	    private String operation_name_TAGNAME;
	    
	    //手术或操作代码
	    private String operation_type_code;
	    private String operation_type_code_TAGNAME;
	    
	    //手术代码
	    private String surg_code;
	    private String surg_code_TAGNAME;
	    
	    //操作代码
	    private String oper_code;
	    private String oper_code_TAGNAME;

	    //是否主要手术或操作
	    private String is_main_operation;
	    private String is_main_operation_TAGNAME;

	    //有无药物过敏
	    private String have_drug_allergy;
	    private String have_drug_allergy_TAGNAME;

	    //病案质量代码
	    private String medical_record_quality;
	    private String medical_record_quality_TAGNAME;

	    //质控医师姓名
	    private String QC_physician_name;
	    private String QC_physician_name_TAGNAME;

	    //质控护士姓名
	    private String QC_nurse_name;
	    private String QC_nurse_name_TAGNAME;

	    //科主任姓名
	    private String dep_director_name;
	    private String dep_director_name_TAGNAME;

	    //主(副主)任医师姓名
	    private String director_doctor_name;
	    private String director_doctor_name_TAGNAME;

	    //主治医师姓名
	    private String physician_name;
	    private String physician_name_TAGNAME;

	    //住院医师姓名
	    private String resident_name;
	    private String resident_name_TAGNAME;

	    //进修医师姓名
	    private String physician_learn_name;
	    private String physician_learn_name_TAGNAME;

	    //实习医师姓名
	    private String intern_name;
	    private String intern_name_TAGNAME;

	    //责任护士姓名
	    private String nurses_name;
	    private String nurses_name_TAGNAME;
	    
	    //主诊医师
	    private String clinic_name;
	    private String clinic_name_TAGNAME;
	    
	    //编码员
	    private String coder_name;
	    private String coder_name_TAGNAME;

	    //呼吸机使用时间(小时)
	    private String ventilator_hours;
	    private String ventilator_hours_TAGNAME;

	    //新生儿出生体重(克)
	    private String birth_weight;
	    private String birth_weight_TAGNAME;

	    //离院方式代码
	    private String out_way;
	    private String out_way_TAGNAME;

	    //医嘱转院、转社区、卫生院机构名称
	    private String turn_name;
	    private String turn_name_TAGNAME;
	    
	    //是否抢救成功
	    private String rescue_success;
	    private String rescue_success_TAGNAME;
	    
	    //抢救次数
	    private String rescue_number;
	    private String rescue_number_TAGNAME;
	    
	    //抢救成功次数
	    private String rescue_success_number;
	    private String rescue_success_number_TAGNAME;

	    //是否有出院31日内再住院计划
	    private String plan_31days;
	    private String plan_31days_TAGNAME;
	    
	    //手术并发症
	    private String complications;
	    private String complications_TAGNAME;

	    //总费用
	    private String total_fee;
	    private String total_fee_TAGNAME;

	    //自付金额
	    private String self_fee;
	    private String self_fee_TAGNAME;

	   /* //诊察（诊疗）费
	    private String fee1;
	    private String fee1_TAGNAME;

	    //一般检查费
	    private String fee2;
	    private String fee2_TAGNAME;

	    //临床物理治疗费
	    private String fee3;
	    private String fee3_TAGNAME;

	    //介入治疗费
	    private String fee4;
	    private String fee4_TAGNAME;

	    //特殊治疗费
	    private String fee5;
	    private String fee5_TAGNAME;

	    //康复治疗费
	    private String fee6;
	    private String fee6_TAGNAME;

	    //中医治疗费
	    private String fee7;
	    private String fee7_TAGNAME;

	    //一般治疗费
	    private String fee8;
	    private String fee8_TAGNAME;

	    //精神治疗费
	    private String fee9;
	    private String fee9_TAGNAME;

	    //接生费
	    private String fee10;
	    private String fee10_TAGNAME;

	    //麻醉费
	    private String fee11;
	    private String fee11_TAGNAME;

	    //手术费
	    private String fee12;
	    private String fee12_TAGNAME;

	    //护理治疗费
	    private String fee13;
	    private String fee13_TAGNAME;

	    //护理费
	    private String fee14;
	    private String fee14_TAGNAME;

	    //核素检查
	    private String fee15;
	    private String fee15_TAGNAME;

	    //核素治疗
	    private String fee16;
	    private String fee16_TAGNAME;

	    //超声费
	    private String fee17;
	    private String fee17_TAGNAME;

	    //放射费
	    private String fee18;
	    private String fee18_TAGNAME;

	    //化验费
	    private String fee19;
	    private String fee19_TAGNAME;

	    //病理费
	    private String fee20;
	    private String fee20_TAGNAME;

	    //监护及辅助呼吸费
	    private String fee21;
	    private String fee21_TAGNAME;

	    //治疗用一次性医用材料费
	    private String fee22;
	    private String fee22_TAGNAME;

	    //介入用一次性医用材料费
	    private String fee23;
	    private String fee23_TAGNAME;

	    //手术用一次性医用材料费
	    private String fee24;
	    private String fee24_TAGNAME;

	    //检查用一次性医用材料费
	    private String fee25;
	    private String fee25_TAGNAME;

	    //床位费
	    private String fee26;
	    private String fee26_TAGNAME;

	    //挂号费
	    private String fee27;
	    private String fee27_TAGNAME;

	    //输氧费
	    private String fee28;
	    private String fee28_TAGNAME;

	    //输血费
	    private String fee29;
	    private String fee29_TAGNAME;

	    //西药费
	    private String fee30;
	    private String fee30_TAGNAME;

	    //抗菌药物费
	    private String fee31;
	    private String fee31_TAGNAME;

	    //白蛋白类制品费
	    private String fee32;
	    private String fee32_TAGNAME;

	    //球蛋白类制品费
	    private String fee33;
	    private String fee33_TAGNAME;

	    //凝血因子类制品费
	    private String fee34;
	    private String fee34_TAGNAME;

	    //细胞因子类制品费
	    private String fee35;
	    private String fee35_TAGNAME;

	    //中成药费
	    private String fee36;
	    private String fee36_TAGNAME;

	    //中草药费
	    private String fee37;
	    private String fee37_TAGNAME;

	    //其他费用
	    private String fee38;
	    private String fee38_TAGNAME;*/
	    
	    private List<String> feeList = new LinkedList<String>();
	    private List<String> fee_TAGNAMEList = new LinkedList<String>();
	    private Map<String,String> fee_TAGNAMEMap = new HashMap<String,String>();
	    private Map<String,String> feeCateMap = new HashMap<String,String>();
	    
	    //病例节点
	    private String patient_TAGNAME;
	    
	    //手术节点
	    private String operation_TAGNAME;
	    
	    //诊断节点
	    private String diagnosis_TAGNAME;
	    
	    //费用节点
	    private String cost_TAGNAME;

		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		SimpleDateFormat sdfDateTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Random random = new Random(100);
		
		//是否有主要诊断
		private boolean hasMainDiag = false;
	    
	    @Override
	    public void startDocument() throws SAXException
	    {
	        System.out.println("start document -> parse begin");
	        
	        List<CostSub> costsubList = costSubApplication.findAllCostSub();
	        
	        //读取配置节点名称
	        adm_No_TAGNAME = properties.getProperty("adm_No");
	        patient_name_TAGNAME = properties.getProperty("patient_name");
	        hosp_inf_TAGNAME = properties.getProperty("hosp_inf");
	        gender_TAGNAME = properties.getProperty("gender");
	        date_of_birth_TAGNAME = properties.getProperty("date_of_birth");
	        age_TAGNAME = properties.getProperty("age");
	        newborns_weight_TAGNAME = properties.getProperty("newborns_weight");
	        newborns_days_TAGNAME = properties.getProperty("newborns_days");
	        marital_status_TAGNAME = properties.getProperty("marital_status");
	        payment_way_TAGNAME = properties.getProperty("payment_way");
	        health_card_No_TAGNAME = properties.getProperty("health_card_No");
	        medical_record_No_TAGNAME = properties.getProperty("medical_record_No");
	        times_of_hospitalizations_TAGNAME = properties.getProperty("times_of_hospitalizations");
	        in_date_TAGNAME = properties.getProperty("in_date");
	        in_time_TAGNAME = properties.getProperty("in_time");
	        in_dep_TAGNAME = properties.getProperty("in_dep");
	        his_in_dep_TAGNAME = properties.getProperty("his_in_dep");
	        in_ward_TAGNAME = properties.getProperty("in_ward");
	        in_way_TAGNAME = properties.getProperty("in_way");
	        out_date_TAGNAME = properties.getProperty("out_date");
	        out_time_TAGNAME = properties.getProperty("out_time");
	        out_dep_TAGNAME = properties.getProperty("out_dep");
	        his_out_dep_TAGNAME = properties.getProperty("his_out_dep");
	        out_ward_TAGNAME = properties.getProperty("out_ward");
	        in_days_TAGNAME = properties.getProperty("in_days");
	        transfer_dep_TAGNAME = properties.getProperty("transfer_dep");
	        door_diagnosis_code_TAGNAME = properties.getProperty("door_diagnosis_code");
	        door_diagnosis_name_TAGNAME = properties.getProperty("door_diagnosis_name");
	        main_diagnosis_code_TAGNAME = properties.getProperty("main_diagnosis_code");
	        main_diagnosis_name_TAGNAME = properties.getProperty("main_diagnosis_name");
	        diagnosis_code_TAGNAME = properties.getProperty("diagnosis_code");
	        diagnosis_name_TAGNAME = properties.getProperty("diagnosis_name");
	        diagnosis_type_code_TAGNAME = properties.getProperty("diagnosis_type_code");
	        in_condition_TAGNAME = properties.getProperty("in_condition");
	        pathological_diagnosis_code_TAGNAME = properties.getProperty("pathological_diagnosis_code");
	        pathological_diagnosis_name_TAGNAME = properties.getProperty("pathological_diagnosis_name");
	        pathological_No_TAGNAME = properties.getProperty("pathological_No");
	        operation_start_time_TAGNAME = properties.getProperty("operation_start_time");
	        operation_end_time_TAGNAME = properties.getProperty("operation_end_time");
	        operation_doctor_TAGNAME = properties.getProperty("operation_doctor");
	        assistant_one_TAGNAME = properties.getProperty("assistant_one");
	        assistant_two_TAGNAME = properties.getProperty("assistant_two");
	        anesthesia_code_TAGNAME = properties.getProperty("anesthesia_code");
	        cut_level_TAGNAME = properties.getProperty("cut_level");
	        anesthesiologists_TAGNAME = properties.getProperty("anesthesiologists");
	        operation_level_TAGNAME = properties.getProperty("operation_level");
	        operation_code_TAGNAME = properties.getProperty("operation_code");
	        operation_name_TAGNAME = properties.getProperty("operation_name");
	        operation_type_code_TAGNAME = properties.getProperty("operation_type_code");
	        surg_code_TAGNAME = properties.getProperty("surg_code");
	        oper_code_TAGNAME = properties.getProperty("oper_code");
	        is_main_operation_TAGNAME = properties.getProperty("is_main_operation");
	        have_drug_allergy_TAGNAME = properties.getProperty("have_drug_allergy");
	        medical_record_quality_TAGNAME = properties.getProperty("medical_record_quality");
	        QC_physician_name_TAGNAME = properties.getProperty("QC_physician_name");
	        QC_nurse_name_TAGNAME = properties.getProperty("QC_nurse_name");
	        dep_director_name_TAGNAME = properties.getProperty("dep_director_name");
	        director_doctor_name_TAGNAME = properties.getProperty("director_doctor_name");
	        physician_name_TAGNAME = properties.getProperty("physician_name");
	        resident_name_TAGNAME = properties.getProperty("resident_name");
	        physician_learn_name_TAGNAME = properties.getProperty("physician_learn_name");
	        intern_name_TAGNAME = properties.getProperty("intern_name");
	        nurses_name_TAGNAME = properties.getProperty("nurses_name");
	        clinic_name_TAGNAME = properties.getProperty("clinic_name");
	        coder_name_TAGNAME = properties.getProperty("coder_name");
	        ventilator_hours_TAGNAME = properties.getProperty("ventilator_hours");
	        birth_weight_TAGNAME = properties.getProperty("birth_weight");
	        out_way_TAGNAME = properties.getProperty("out_way");
	        turn_name_TAGNAME = properties.getProperty("turn_name");
	        rescue_success_TAGNAME = properties.getProperty("rescue_success");
	        rescue_number_TAGNAME = properties.getProperty("rescue_number");
	        rescue_success_number_TAGNAME = properties.getProperty("rescue_success_number");
	        plan_31days_TAGNAME = properties.getProperty("plan_31days");
	        complications_TAGNAME = properties.getProperty("complications");
	        total_fee_TAGNAME = properties.getProperty("total_fee");
	        self_fee_TAGNAME = properties.getProperty("self_fee");
	        for (CostSub costSub:costsubList) {
				fee_TAGNAMEMap.put("fee"+costSub.getCostSubcode(), properties.getProperty("fee"+costSub.getCostSubcode()));
				feeCateMap.put("fee"+costSub.getCostSubcode(), costSub.getParcostCatecode());
			}
	        /*fee1_TAGNAME = properties.getProperty("fee1");
	        fee2_TAGNAME = properties.getProperty("fee2");
	        fee3_TAGNAME = properties.getProperty("fee3");
	        fee4_TAGNAME = properties.getProperty("fee4");
	        fee5_TAGNAME = properties.getProperty("fee5");
	        fee6_TAGNAME = properties.getProperty("fee6");
	        fee7_TAGNAME = properties.getProperty("fee7");
	        fee8_TAGNAME = properties.getProperty("fee8");
	        fee9_TAGNAME = properties.getProperty("fee9");
	        fee10_TAGNAME = properties.getProperty("fee10");
	        fee11_TAGNAME = properties.getProperty("fee11");
	        fee12_TAGNAME = properties.getProperty("fee12");
	        fee13_TAGNAME = properties.getProperty("fee13");
	        fee14_TAGNAME = properties.getProperty("fee14");
	        fee15_TAGNAME = properties.getProperty("fee15");
	        fee16_TAGNAME = properties.getProperty("fee16");
	        fee17_TAGNAME = properties.getProperty("fee17");
	        fee18_TAGNAME = properties.getProperty("fee18");
	        fee19_TAGNAME = properties.getProperty("fee19");
	        fee20_TAGNAME = properties.getProperty("fee20");
	        fee21_TAGNAME = properties.getProperty("fee21");
	        fee22_TAGNAME = properties.getProperty("fee22");
	        fee23_TAGNAME = properties.getProperty("fee23");
	        fee24_TAGNAME = properties.getProperty("fee24");
	        fee25_TAGNAME = properties.getProperty("fee25");
	        fee26_TAGNAME = properties.getProperty("fee26");
	        fee27_TAGNAME = properties.getProperty("fee27");
	        fee28_TAGNAME = properties.getProperty("fee28");
	        fee29_TAGNAME = properties.getProperty("fee29");
	        fee30_TAGNAME = properties.getProperty("fee30");
	        fee31_TAGNAME = properties.getProperty("fee31");
	        fee32_TAGNAME = properties.getProperty("fee32");
	        fee33_TAGNAME = properties.getProperty("fee33");
	        fee34_TAGNAME = properties.getProperty("fee34");
	        fee35_TAGNAME = properties.getProperty("fee35");
	        fee36_TAGNAME = properties.getProperty("fee36");
	        fee37_TAGNAME = properties.getProperty("fee37");
	        fee38_TAGNAME = properties.getProperty("fee38");*/
	        
	        patient_TAGNAME = properties.getProperty("patient");
	        operation_TAGNAME = properties.getProperty("operation");
	        diagnosis_TAGNAME = properties.getProperty("diagnosis");
	        cost_TAGNAME = properties.getProperty("cost");
	        
	        main_diagnosis_type_code = properties.getProperty("main_diagnosis_type_code");
	        door_diagnosis_type_code = properties.getProperty("door_diagnosis_type_code");
	        other_diagnosis_type_code = properties.getProperty("other_diagnosis_type_code");
	        surg_code = properties.getProperty("surg_code");
	        oper_code = properties.getProperty("oper_code");
	    }

	    @Override
	    public void endDocument() throws SAXException
	    {

	        System.out.println("end document -> parse finished");
	    }

	    @Override
	    public void startElement(String uri, String localName, String qName,
	            Attributes attributes) throws SAXException
	    {
	        // 将标签名压入栈
	        stack.push(qName);
	        
	        if (patient_TAGNAME.equals(qName)) {
	        	hasMainDiag = false;
	        }

	    }

	    @Override
	    public void characters(char[] ch, int start, int length)
	            throws SAXException
	    {
	        // 取出标签名
	        String tagName = stack.peek();
	        String tagValue = new String(ch, start, length);
	        if (tagName.equals(adm_No_TAGNAME)) {
	        	adm_No = tagValue;
	        }
	        else if (tagName.equals(patient_name_TAGNAME)) {
	        	patient_name = tagValue;
	        }
	        else if (tagName.equals(hosp_inf_TAGNAME)) {
	        	hosp_inf = tagValue;
	        }
	        else if (tagName.equals(gender_TAGNAME)) {
	        	gender = tagValue;
	        	System.out.println("=============  gender:"+tagValue);
	        }
	        else if (tagName.equals(date_of_birth_TAGNAME)) {
	        	date_of_birth = tagValue;
	        }
	        else if (tagName.equals(age_TAGNAME)) {
	        	age = tagValue;
	        }
	        else if (tagName.equals(newborns_weight_TAGNAME)) {
	        	newborns_weight = tagValue;
	        }
	        else if (tagName.equals(newborns_days_TAGNAME)) {
	        	newborns_days = tagValue;
	        }
	        else if (tagName.equals(marital_status_TAGNAME)) {
	        	marital_status = tagValue;
	        }
	        else if (tagName.equals(payment_way_TAGNAME)) {
	        	payment_way = tagValue;
	        }
	        else if (tagName.equals(health_card_No_TAGNAME)) {
	        	health_card_No = tagValue;
	        }
	        else if (tagName.equals(medical_record_No_TAGNAME)) {
	        	medical_record_No = tagValue;
	        }
	        else if (tagName.equals(times_of_hospitalizations_TAGNAME)) {
	        	times_of_hospitalizations = tagValue;
	        }
	        else if (tagName.equals(in_date_TAGNAME)) {
	        	in_date = tagValue;
	        }
	        else if (tagName.equals(in_time_TAGNAME)) {
	        	in_time = tagValue;
	        }
	        else if (tagName.equals(in_dep_TAGNAME)) {
	        	in_dep = tagValue;
	        }
	        else if (tagName.equals(his_in_dep_TAGNAME)) {
	        	his_in_dep = tagValue;
	        }
	        else if (tagName.equals(in_ward_TAGNAME)) {
	        	in_ward = tagValue;
	        }
	        else if (tagName.equals(in_way_TAGNAME)) {
	        	in_way = tagValue;
	        }
	        else if (tagName.equals(out_date_TAGNAME)) {
	        	out_date = tagValue;
	        }
	        else if (tagName.equals(out_time_TAGNAME)) {
	        	out_time = tagValue;
	        }
	        else if (tagName.equals(out_dep_TAGNAME)) {
	        	out_dep = tagValue;
	        }
	        else if (tagName.equals(his_out_dep_TAGNAME)) {
	        	his_out_dep = tagValue;
	        }
	        else if (tagName.equals(out_ward_TAGNAME)) {
	        	out_ward = tagValue;
	        }
	        else if (tagName.equals(in_days_TAGNAME)) {
	        	in_days = tagValue;
	        }
	        else if (tagName.equals(transfer_dep_TAGNAME)) {
	        	transfer_dep = tagValue;
	        }
	        else if (tagName.equals(door_diagnosis_code_TAGNAME)) {
	        	door_diagnosis_code = tagValue;
	        }
	        else if (tagName.equals(door_diagnosis_name_TAGNAME)) {
	        	door_diagnosis_name = tagValue;
	        }
	        else if (tagName.equals(main_diagnosis_code_TAGNAME)) {
	        	main_diagnosis_code = tagValue;
	        }
	        else if (tagName.equals(main_diagnosis_name_TAGNAME)) {
	        	main_diagnosis_name = tagValue;
	        }
	        else if (tagName.equals(diagnosis_code_TAGNAME)) {
	        	diagnosis_code = tagValue;
	        }
	        else if (tagName.equals(diagnosis_name_TAGNAME)) {
	        	diagnosis_name = tagValue;
	        }
	        else if (tagName.equals(diagnosis_type_code_TAGNAME)) {
	        	diagnosis_type_code = tagValue;
	        }
	        else if (tagName.equals(in_condition_TAGNAME)) {
	        	in_condition = tagValue;
	        }
	        else if (tagName.equals(pathological_diagnosis_code_TAGNAME)) {
	        	pathological_diagnosis_code = tagValue;
	        }
	        else if (tagName.equals(pathological_diagnosis_name_TAGNAME)) {
	        	pathological_diagnosis_name = tagValue;
	        }
	        else if (tagName.equals(pathological_No_TAGNAME)) {
	        	pathological_No = tagValue;
	        }
	        else if (tagName.equals(operation_start_time_TAGNAME)) {
	        	operation_start_time = tagValue;
	        }
	        else if (tagName.equals(operation_end_time_TAGNAME)) {
	        	operation_end_time = tagValue;
	        }
	        else if (tagName.equals(operation_doctor_TAGNAME)) {
	        	operation_doctor = tagValue;
	        }
	        else if (tagName.equals(assistant_one_TAGNAME)) {
	        	assistant_one = tagValue;
	        }
	        else if (tagName.equals(assistant_two_TAGNAME)) {
	        	assistant_two = tagValue;
	        }
	        else if (tagName.equals(anesthesia_code_TAGNAME)) {
	        	anesthesia_code = tagValue;
	        }
	        else if (tagName.equals(cut_level_TAGNAME)) {
	        	cut_level = tagValue;
	        }
	        else if (tagName.equals(anesthesiologists_TAGNAME)) {
	        	anesthesiologists = tagValue;
	        }
	        else if (tagName.equals(operation_level_TAGNAME)) {
	        	operation_level = tagValue;
	        }
	        else if (tagName.equals(operation_code_TAGNAME)) {
	        	operation_code = tagValue;
	        }
	        else if (tagName.equals(operation_name_TAGNAME)) {
	        	operation_name = tagValue;
	        }
	        else if (tagName.equals(operation_type_code_TAGNAME)) {
	        	operation_type_code = tagValue;
	        }
	        else if (tagName.equals(is_main_operation_TAGNAME)) {
	        	is_main_operation = tagValue;
	        }
	        else if (tagName.equals(have_drug_allergy_TAGNAME)) {
	        	have_drug_allergy = tagValue;
	        }
	        else if (tagName.equals(medical_record_quality_TAGNAME)) {
	        	medical_record_quality = tagValue;
	        }
	        else if (tagName.equals(QC_physician_name_TAGNAME)) {
	        	QC_physician_name = tagValue;
	        }
	        else if (tagName.equals(QC_nurse_name_TAGNAME)) {
	        	QC_nurse_name = tagValue;
	        }
	        else if (tagName.equals(dep_director_name_TAGNAME)) {
	        	dep_director_name = tagValue;
	        }
	        else if (tagName.equals(director_doctor_name_TAGNAME)) {
	        	director_doctor_name = tagValue;
	        }
	        else if (tagName.equals(physician_name_TAGNAME)) {
	        	physician_name = tagValue;
	        }
	        else if (tagName.equals(resident_name_TAGNAME)) {
	        	resident_name = tagValue;
	        }
	        else if (tagName.equals(physician_learn_name_TAGNAME)) {
	        	physician_learn_name = tagValue;
	        }
	        else if (tagName.equals(intern_name_TAGNAME)) {
	        	intern_name = tagValue;
	        }
	        else if (tagName.equals(nurses_name_TAGNAME)) {
	        	nurses_name = tagValue;
	        }
	        else if (tagName.equals(clinic_name_TAGNAME)) {
	        	clinic_name = tagValue;
	        }
	        else if (tagName.equals(coder_name_TAGNAME)) {
	        	coder_name = tagValue;
	        }
	        else if (tagName.equals(ventilator_hours_TAGNAME)) {
	        	ventilator_hours = tagValue;
	        }
	        else if (tagName.equals(birth_weight_TAGNAME)) {
	        	birth_weight = tagValue;
	        }
	        else if (tagName.equals(out_way_TAGNAME)) {
	        	out_way = tagValue;
	        }
	        else if (tagName.equals(turn_name_TAGNAME)) {
	        	turn_name = tagValue;
	        }
	        else if (tagName.equals(rescue_success_TAGNAME)) {
	        	rescue_success = tagValue;
	        }
	        else if (tagName.equals(rescue_number_TAGNAME)) {
	        	rescue_number = tagValue;
	        }
	        else if (tagName.equals(rescue_success_number_TAGNAME)) {
	        	rescue_success_number = tagValue;
	        }
	        else if (tagName.equals(plan_31days_TAGNAME)) {
	        	plan_31days = tagValue;
	        }
	        else if (tagName.equals(complications_TAGNAME)) {
	        	complications = tagValue;
	        }
	        else if (tagName.equals(total_fee_TAGNAME)) {
	        	total_fee = tagValue;
	        }
	        else if (tagName.equals(self_fee_TAGNAME)) {
	        	self_fee = tagValue;
	        	System.out.println("============== self_fee:"+tagValue);
	        }
	        
	        for(String str:fee_TAGNAMEMap.keySet()){
	        	if(tagName.equals(fee_TAGNAMEMap.get(str))){
	        		costMap.put(str, tagValue);
	        		if("1".equals(feeCateMap.get(str))){
	        			drugFee += toDouble(tagValue);//计算药品费
	        		}else if("2".equals(feeCateMap.get(str))){
		        		materialFee += toDouble(tagValue);//计算材料费
		        	}
	        	}
	        }
	        /*else if (tagName.equals(fee1_TAGNAME)) {
	        	costMap.put("fee1", tagValue);
	        }
	        else if (tagName.equals(fee2_TAGNAME)) {
	        	costMap.put("fee2", tagValue);
	        }
	        else if (tagName.equals(fee3_TAGNAME)) {
	        	costMap.put("fee3", tagValue);
	        }
	        else if (tagName.equals(fee4_TAGNAME)) {
	        	costMap.put("fee4", tagValue);
	        }
	        else if (tagName.equals(fee5_TAGNAME)) {
	        	costMap.put("fee5", tagValue);
	        }
	        else if (tagName.equals(fee6_TAGNAME)) {
	        	costMap.put("fee6", tagValue);
	        }
	        else if (tagName.equals(fee7_TAGNAME)) {
	        	costMap.put("fee7", tagValue);
	        }
	        else if (tagName.equals(fee8_TAGNAME)) {
	        	costMap.put("fee8", tagValue);
	        }
	        else if (tagName.equals(fee9_TAGNAME)) {
	        	costMap.put("fee9", tagValue);
	        }
	        else if (tagName.equals(fee10_TAGNAME)) {
	        	costMap.put("fee10", tagValue);
	        }
	        else if (tagName.equals(fee11_TAGNAME)) {
	        	costMap.put("fee11", tagValue);
	        }
	        else if (tagName.equals(fee12_TAGNAME)) {
	        	costMap.put("fee12", tagValue);
	        }
	        else if (tagName.equals(fee13_TAGNAME)) {
	        	costMap.put("fee13", tagValue);
	        }
	        else if (tagName.equals(fee14_TAGNAME)) {
	        	costMap.put("fee14", tagValue);
	        }
	        else if (tagName.equals(fee15_TAGNAME)) {
	        	costMap.put("fee15", tagValue);
	        }
	        else if (tagName.equals(fee16_TAGNAME)) {
	        	costMap.put("fee16", tagValue);
	        }
	        else if (tagName.equals(fee17_TAGNAME)) {
	        	costMap.put("fee17", tagValue);
	        }
	        else if (tagName.equals(fee18_TAGNAME)) {
	        	costMap.put("fee18", tagValue);
	        }
	        else if (tagName.equals(fee19_TAGNAME)) {
	        	costMap.put("fee19", tagValue);
	        }
	        else if (tagName.equals(fee20_TAGNAME)) {
	        	costMap.put("fee20", tagValue);
	        }
	        else if (tagName.equals(fee21_TAGNAME)) {
	        	costMap.put("fee21", tagValue);
	        }
	        else if (tagName.equals(fee22_TAGNAME)) {
	        	costMap.put("fee22", tagValue);
	        	materialFee += toDouble(tagValue);//计算材料费
	        }
	        else if (tagName.equals(fee23_TAGNAME)) {
	        	costMap.put("fee23", tagValue);
	        	materialFee += toDouble(tagValue);//计算材料费
	        }
	        else if (tagName.equals(fee24_TAGNAME)) {
	        	costMap.put("fee24", tagValue);
	        	materialFee += toDouble(tagValue);//计算材料费
	        }
	        else if (tagName.equals(fee25_TAGNAME)) {
	        	costMap.put("fee25", tagValue);
	        	materialFee += toDouble(tagValue);//计算材料费
	        }
	        else if (tagName.equals(fee26_TAGNAME)) {
	        	costMap.put("fee26", tagValue);
	        }
	        else if (tagName.equals(fee27_TAGNAME)) {
	        	costMap.put("fee27", tagValue);
	        }
	        else if (tagName.equals(fee28_TAGNAME)) {
	        	costMap.put("fee28", tagValue);
	        }
	        else if (tagName.equals(fee29_TAGNAME)) {
	        	costMap.put("fee29", tagValue);
	        }
	        else if (tagName.equals(fee30_TAGNAME)) {
	        	costMap.put("fee30", tagValue);
	        	drugFee  += toDouble(tagValue);//计算药品费用
	        }
	        else if (tagName.equals(fee31_TAGNAME)) {
	        	costMap.put("fee31", tagValue);
	        	drugFee  += toDouble(tagValue);//计算药品费用
	        }
	        else if (tagName.equals(fee32_TAGNAME)) {
	        	costMap.put("fee32", tagValue);
	        }
	        else if (tagName.equals(fee33_TAGNAME)) {
	        	costMap.put("fee33", tagValue);
	        }
	        else if (tagName.equals(fee34_TAGNAME)) {
	        	costMap.put("fee34", tagValue);
	        }
	        else if (tagName.equals(fee35_TAGNAME)) {
	        	costMap.put("fee35", tagValue);
	        }
	        else if (tagName.equals(fee36_TAGNAME)) {
	        	costMap.put("fee36", tagValue);
	        	drugFee  += toDouble(tagValue);//计算药品费用
	        }
	        else if (tagName.equals(fee37_TAGNAME)) {
	        	costMap.put("fee37", tagValue);
	        	drugFee  += toDouble(tagValue);//计算药品费用
	        }
	        else if (tagName.equals(fee38_TAGNAME)) {
	        	costMap.put("fee38", tagValue);
	        }*/
	    }

	    @Override
	    public void endElement(String uri, String localName, String qName)
	            throws SAXException
	    {
	        stack.pop();// 表示该元素解析完毕，需要从栈中弹出标签

	        if (operation_TAGNAME.equals(qName))
	        {/*
	    //        Operation oper = new Operation();
	            oper.setId(UUID.randomUUID().toString());
	            oper.setParid(medical_record_No+"-"+out_date.replaceAll(".\\d{2}:\\d{2}(:\\d{2})?", "")+"-"+Integer.parseInt(times_of_hospitalizations));
	           
	            oper.setOperCode(operation_code);
	            oper.setOperation(operation_name);
	            if (!StringUtils.isBlank(operation_start_time)) {
	            	try {
						oper.setOperStime(sdfDateTime.parse(operation_start_time));
					} catch (ParseException e) {
						System.err.println("手术时间解析异常！");
						e.printStackTrace();
					}
				}
	            if (!StringUtils.isBlank(operation_end_time)) {
	            	try {
						oper.setOperEtime(sdfDateTime.parse(operation_end_time));
					} catch (ParseException e) {
						System.err.println("手术时间解析异常！");
						e.printStackTrace();
					}
				}
	            oper.setOperDoctor(operation_doctor);
	            oper.setAssisOne(assistant_one);
	            oper.setAssisTwo(assistant_two);
	            oper.setAnaesWay(anesthesia_code);
	            oper.setCutLevel(cut_level);
	            oper.setAnaesDoctor(anesthesiologists);
	            oper.setOperLevel(operation_level);
	            if (surg_code != null && !"".equals(surg_code) && surg_code.equals(operation_type_code)) {
					oper.setIsOper("1");// 手术
					if((!"".equals(is_main_operation) && is_main_operation != null)){
							 if("1".equals(is_main_operation) || "true".equals(is_main_operation)){
						oper.setOperType("M");// 主要手术
							 }else{
						oper.setOperType("O");// 其他手术
							 }
					}
					else{
					if (surg_index == 1) {
						oper.setOperType("M");// 主要手术
					} else {
						oper.setOperType("O");// 其他手术
					}
					surg_index++;
					}
					
				} else if (oper_code != null && !"".equals(oper_code) && oper_code.equals(operation_type_code)) {
					oper.setIsOper("0");// 操作
					if((!"".equals(is_main_operation) && is_main_operation != null)){
						 if("1".equals(is_main_operation) || "true".equals(is_main_operation)){
					oper.setOperType("M");// 主要操作
						 }else {
					oper.setOperType("O");// 其他操作
						 }
				}else{
					if (oper_index == 1) {
						oper.setOperType("M");// 主要操作
					} else {
						oper.setOperType("O");// 其他操作
					}
					oper_index++;
				}
				}else{
					if((!"".equals(is_main_operation) && is_main_operation != null)){
						 if("1".equals(is_main_operation) || "true".equals(is_main_operation)){
					oper.setOperType("M");// 主要手术
						 }else{
					oper.setOperType("O");// 其他手术
						 }
				}else{
					if (surg_index==1) {
						oper.setOperType("M");//主要手术
					} else {
						oper.setOperType("O");// 其他手术
					}
					surg_index++;
					}
				}
	            
	            if(null != oper.getOperCode() && !"null".equals(oper.getOperCode()) && !"".equals(oper.getOperCode()) 
	            		&& null != oper.getOperation() && !"null".equals(oper.getOperation()) && !"".equals(oper.getOperation())){
	            	 operList.add(oper);
	            }
	            
	            //重新初始化手术的值
	            operation_code="";
	            operation_name="";
	            operation_start_time="";
	            operation_end_time="";
	            operation_doctor="";
	            assistant_one="";
	            assistant_two="";
	            anesthesia_code="";
	            cut_level="";
	            anesthesiologists="";
	            operation_level="";
	            operation_type_code="";
	            is_main_operation="";
	        */}
	        if (diagnosis_TAGNAME.equals(qName)) 
	        {
				if (diagnosis_type_code!=null && diagnosis_type_code.equals(main_diagnosis_type_code)) {/*
					main_diagnosis_code = diagnosis_code;
					main_diagnosis_name = diagnosis_name;
					
					Diagnosis diag = new Diagnosis();
					diag.setId(UUID.randomUUID().toString());
					diag.setParid(medical_record_No+"-"+out_date.replaceAll(".\\d{2}:\\d{2}(:\\d{2})?", "")+"-"+Integer.parseInt(times_of_hospitalizations));
					diag.setDiagCode(diagnosis_code);
					diag.setDiagnosis(diagnosis_name);
					diag.setInCondition(in_condition);
					diag.setDiagTypecode("M");//【安贞】21:主要诊断，22:其他诊断，23:门急诊诊断
					diag.setDiagType("主要诊断");
					
					hasMainDiag = true;
					
					 if(null != diag.getDiagCode() && !"null".equals(diag.getDiagCode()) && !"".equals(diag.getDiagCode())
							 && null != diag.getDiagnosis() && !"null ".equals(diag.getDiagnosis()) && !"".equals(diag.getDiagnosis())){
						 diagList.add(diag);
		            }
					
					//重新初始化诊断的值
					diagnosis_code="";
					diagnosis_name="";
					in_condition="";
					
				*/} else if (diagnosis_type_code!=null && diagnosis_type_code.equals(door_diagnosis_type_code)) {
					door_diagnosis_code = diagnosis_code;
					door_diagnosis_name = diagnosis_name;
				} else if (diagnosis_type_code!=null && diagnosis_type_code.equals(other_diagnosis_type_code)) {
				//	Diagnosis diag = new Diagnosis();
					/*diag.setId(UUID.randomUUID().toString());
					diag.setParid(medical_record_No+"-"+out_date.replaceAll(".\\d{2}:\\d{2}(:\\d{2})?", "")+"-"+Integer.parseInt(times_of_hospitalizations));
					diag.setDiagCode(diagnosis_code);
					diag.setDiagnosis(diagnosis_name);
					diag.setInCondition(in_condition);
					diag.setDiagTypecode("O");//【安贞】21:主要诊断，22:其他诊断，23:门急诊诊断
					diag.setDiagType("其他诊断");*/
					
					//diagList.add(diag);
					
					//重新初始化诊断的值
					diagnosis_code="";
					diagnosis_name="";
					in_condition="";
				} else if (diagnosis_type_code==null) {
					//若诊断列表没有区分诊断类型（即diagnosis_type_code==null），则默认全部都是其他诊断
					//Diagnosis diag = new Diagnosis();
/*					diag.setId(UUID.randomUUID().toString());
					diag.setParid(medical_record_No+"-"+out_date.replaceAll(".\\d{2}:\\d{2}(:\\d{2})?", "")+"-"+Integer.parseInt(times_of_hospitalizations));
					diag.setDiagCode(diagnosis_code);
					diag.setDiagnosis(diagnosis_name);
					diag.setInCondition(in_condition);
					diag.setDiagTypecode("O");//【安贞】21:主要诊断，22:其他诊断，23:门急诊诊断
					diag.setDiagType("其他诊断")*/;
					
				//	diagList.add(diag);
					
					//重新初始化诊断的值
					diagnosis_code="";
					diagnosis_name="";
					in_condition="";
				}
				/*  //只存主要诊断和其他诊断，所以注释掉以下else内的代码
				else {
					Diagnosis diag = new Diagnosis();
					diag.setId(UUID.randomUUID().toString());
					diag.setParid(medical_record_No+"-"+out_date);
					diag.setDiagCode(diagnosis_code);
					diag.setDiagnosis(diagnosis_name);
					diag.setInCondition(in_condition);
					diag.setDiagTypecode(diagnosis_type_code);//【安贞】21:主要诊断，22:其他诊断，23:门急诊诊断
					//diag.setDiagType();
					
					diagList.add(diag);
				}
				*/
			}
	        if (cost_TAGNAME.equals(qName)) 
	        {
	        	for (String costTagName : costMap.keySet()) {
	        		if (costCodeMap.get(tagDescMap.get(costTagName))!=null) {/*
	        			Cost cost = new Cost();
	        			if(times_of_hospitalizations != null && !"".equals(times_of_hospitalizations)){
	        				cost.setParid(medical_record_No+"-"+out_date.replaceAll(".\\d{2}:\\d{2}(:\\d{2})?", "")+"-"+Integer.parseInt(times_of_hospitalizations));
	        			}else{
	        				cost.setParid(medical_record_No+"-"+out_date.replaceAll(".\\d{2}:\\d{2}(:\\d{2})?", ""));
	        			}
						cost.setId(System.currentTimeMillis()+""+random.nextLong());
						cost.setParcostSubcode(costCodeMap.get(tagDescMap.get(costTagName)));
						cost.setCost(toDouble(costMap.get(costTagName)));
						costList.add(cost);
					*/}
				}
			}
	        
	        if (patient_TAGNAME.equals(qName)) {
				MedicalRecord mr = new MedicalRecord();
				mr.setId(medical_record_No+"-"+out_date.replaceAll(".\\d{2}:\\d{2}(:\\d{2})?", "")+"-"+Integer.parseInt(times_of_hospitalizations));
				mr.setPatientName(patient_name);
				mr.setRecordId(adm_No);
				mr.setSex(gender);
				mr.setAgeYear(toDouble(age));
				mr.setNewbornWeight(toDouble(newborns_weight));
				mr.setNewbornDays(toDouble(newborns_days));
				mr.setMarriage(marital_status);
				mr.setPayment(payment_way);
				mr.setMrNo(medical_record_No);
				mr.setIpCount(toDouble(times_of_hospitalizations));
				
				//科室和病区
				List<Department> depList = departmentApplication.findAllDepartment();
		        Map<String,String> depMap = new HashMap<String,String>();
		        for(Department dep:depList){
		        	depMap.put(dep.getDepName(), dep.getDepCode());
		        }
		        
				if(in_dep != null && !"".equals(in_dep)){
					in_dep = in_dep.replaceAll("\\s*", "");
					String depCode = depMap.get(in_dep);
					mr.setInDep(in_dep);
					if(null != depCode){
						mr.setInDepcode(depCode);
					}else{
						SimpleDateFormat formatter = new SimpleDateFormat("yyMMddHHmmssSSS");
						String formatStr =formatter.format(new Date());
						depMap.put(in_dep,formatStr);//把新的科室存到map里面
						mr.setInDepcode(formatStr);
						//增加一个特殊的科室组
						DepGroup dg = depGroupApplication.getDepGroup("XZKSKSZ");
						if(dg == null)
						{
							dg = new DepGroup();
							dg.setDepGroupCode("XZKSKSZ");
							dg.setDepGroupDesc("新增科室科室组");
							depGroupApplication.creatDepGroup(dg);
						}
						//把科室存到数据库里面
						Department department = new Department();
						department.setDepCode(formatStr);
						department.setDepName(in_dep);
						department.setParDepGroupCode("XZKSKSZ");
						departmentApplication.creatDepartment(department);
					}
				}
				
				//mr.setInDepcode(getDepCode(in_dep));
//				if (getDepName(in_dep) != null) {
//					mr.setInDep(getDepName(in_dep));
//					mr.setInDepcode(getDepCode(in_dep));
//				}
				
				/*
				else {
					//先用HIS科室
					if (hisDepNameMap.get(his_in_dep)!=null) {
						mr.setInDep(hisDepNameMap.get(his_in_dep));
						mr.setInDepcode(hisDepCodeMap.get(his_in_dep));
					}
					
					if (mr.getInDep() == null && wardDepNameMap.get(in_ward) != null) {
						mr.setInDep(getDepName(wardDepNameMap.get(in_ward)));//获取病房所属科室名【安贞】
						mr.setInDepcode(getDepCode(wardDepNameMap.get(in_ward)));
					}
				}
				*/
				
				if(out_dep != null && !"".equals(out_dep)){
					out_dep = out_dep.replaceAll("\\s*", "");
					String depCode = depMap.get(out_dep);
					mr.setOutDep(out_dep);
					if(null != depCode){
						mr.setOutDepcode(depCode);
					}else{
						SimpleDateFormat formatter = new SimpleDateFormat("yyMMddHHmmssSSS");
						String formatStr =formatter.format(new Date());
						depMap.put(out_dep,formatStr);//把新的科室存到map里面
						mr.setOutDepcode(formatStr);
						//增加一个特殊的科室组
						DepGroup dg = depGroupApplication.getDepGroup("XZKSKSZ");
						if(dg == null)
						{
							dg = new DepGroup();
							dg.setDepGroupCode("XZKSKSZ");
							dg.setDepGroupDesc("新增科室科室组");
							depGroupApplication.creatDepGroup(dg);
						}
						//把科室存到数据库里面
						Department department = new Department();
						department.setDepCode(formatStr);
						department.setDepName(out_dep);
						department.setParDepGroupCode("XZKSKSZ");
						departmentApplication.creatDepartment(department);
					}
				}
//				if(out_dep != null) out_dep = out_dep.replaceAll("\\s*", "");
//				mr.setOutDep(out_dep);
//				//mr.setOutDepcode(getDepCode(out_dep));
//				if (getDepName(out_dep) != null) {
//					mr.setOutDep(getDepName(out_dep));
//					mr.setOutDepcode(getDepCode(out_dep));
//				}
				
				/*
				else {
					//先用HIS科室
					if (hisDepNameMap.get(his_out_dep)!=null) {
						mr.setOutDep(hisDepNameMap.get(his_out_dep));
						mr.setOutDepcode(hisDepCodeMap.get(his_out_dep));
					}
					
					if (mr.getOutDep() == null && wardDepNameMap.get(out_ward) != null) {
						mr.setOutDep(getDepName(wardDepNameMap.get(out_ward)));//获取病房所属科室名【安贞】
						mr.setOutDepcode(getDepCode(wardDepNameMap.get(out_ward)));
					}
				}
				*/
				mr.setInWard(in_ward);
				mr.setOutWard(out_ward);
				
				mr.setInDays(toDouble(in_days));
				mr.setTransDepDesc(transfer_dep);
				mr.setDiagnoseCodemain(main_diagnosis_code);
				mr.setDiagnoseDessmain(main_diagnosis_name);
				mr.setOpDiagnosiscode(door_diagnosis_code);
				mr.setOpDiagnosis(door_diagnosis_name);
				mr.setMrQuality(medical_record_quality);
				mr.setDepMaster(dep_director_name);
				mr.setProtomedicus(director_doctor_name);
				mr.setPhysician(physician_name);
				mr.setResidentDoctor(resident_name);
				mr.setPhysicianLearn(physician_learn_name);
				mr.setIntern(intern_name);
				mr.setNurse(nurses_name);
				mr.setPargroupName(clinic_name);
				mr.setCoder(coder_name);
				mr.setVentilatorHour(toDouble(ventilator_hours));
				mr.setOutWay(out_way);
				mr.setCostamount(toDouble(total_fee));
				mr.setCostself(toDouble(self_fee));
				mr.setTransDepDesc(transfer_dep);
				mr.setInfectionCase(hosp_inf);
				mr.setDrugcost(drugFee);
				mr.setMaterialcost(materialFee);
				try {
					mr.setDayOfbirth(sdf.parse(date_of_birth));
					mr.setInDate(sdf.parse(in_date));
					mr.setOutDate(sdf.parse(out_date));
				} catch (ParseException e) {
					System.err.println("日期解析错误！");
					e.printStackTrace();
				}
				
				//住院时间为空处理
				if(mr.getInDays() == 0.0 && mr.getOutDate() != null && mr.getInDate() != null){
					mr.setInDays(toDouble((mr.getOutDate().getTime() - mr.getInDate().getTime())/(1000*3600*24)));
				}
				//新生儿天数为空的处理
				if(mr.getNewbornDays() == 0.0 && mr.getInDate() != null && mr.getDayOfbirth() != null){
					double newBornDays = (mr.getInDate().getTime() - mr.getDayOfbirth().getTime())/(1000*3600*24);
					if(newBornDays <= 365){
						if(newBornDays == 0){
							mr.setNewbornDays(newBornDays+1);
						}else{
							mr.setNewbornDays(newBornDays);
						}
					}
				}
				
				//是否使用抗菌药物，fee31:抗菌药物费代码
				if (StringUtils.isEmpty(costMap.get("fee31")) || "0".equals(costMap.get("fee31"))) {
					mr.setUseanticase("0");
				} else {
					mr.setUseanticase("1");
				}
				
				//是否抢救成功
				if (StringUtils.isEmpty(rescue_success)) {
					if (toDouble(rescue_number) > 0 && toDouble(rescue_success_number) >= toDouble(rescue_number)) {
						//如果抢救次数大于0，并且抢救成功次数大于或等于抢救次数，则抢救成功
						mr.setRescueSuccessCase("1");
					} else if (toDouble(rescue_number) > 0 && toDouble(rescue_success_number) < toDouble(rescue_number)) {
						//如果抢救次数大于0，并且抢救成功次数小于抢救次数，则抢救不成功
						mr.setRescueSuccessCase("0");
					}
				} else {
					mr.setRescueSuccessCase(rescue_success);
				}
				
				if (StringUtils.isEmpty(complications) || "无".equals(complications)) {
					mr.setComplicationscase("0");
				} else {
					mr.setComplicationscase("1");
					mr.setComplications(complications);
				}
				
				//添加主要诊断到诊断表
				if( ! hasMainDiag){/*
					Diagnosis diag = new Diagnosis();
					diag.setId(UUID.randomUUID().toString());
					diag.setParid(medical_record_No+"-"+out_date.replaceAll(".\\d{2}:\\d{2}(:\\d{2})?", "")+"-"+Integer.parseInt(times_of_hospitalizations));
					diag.setDiagCode(main_diagnosis_code);
					diag.setDiagnosis(main_diagnosis_name);
					diag.setDiagTypecode("M");
					diag.setDiagType("主要诊断");
					
					diagList.add(diag);
				*/}
				
				mrList.add(mr);
				
				//重新初始化首页表的值
				medical_record_No="";
				out_date="";
				patient_name="";
				adm_No="";
				gender="";
				age="";
				newborns_days="";
				newborns_weight="";
				marital_status="";
				payment_way="";
				medical_record_No="";
				times_of_hospitalizations="";
				in_dep="";
				his_in_dep="";
				in_ward="";
				out_dep="";
				his_out_dep="";
				out_ward="";
				in_days="";
				transfer_dep="";
				main_diagnosis_code="";
				main_diagnosis_name="";
				door_diagnosis_code="";
				door_diagnosis_name="";
				medical_record_quality="";
				dep_director_name="";
				director_doctor_name="";
				physician_name="";
				resident_name="";
				physician_learn_name="";
				intern_name="";
				nurses_name="";
				clinic_name="";
				coder_name="";
				ventilator_hours="";
				out_way="";
				total_fee="";
				self_fee="";
				transfer_dep="";
				hosp_inf="";
				rescue_success="";
				rescue_number="";
				rescue_success_number="";
				date_of_birth="";
				in_date="";
				out_date="";
				drugFee = 0;
				materialFee = 0;
				
				surg_index=1;
				oper_index=1;
			}

	    }
	    
	    private String getDepCode(String depName) {
	    	if (depCodeMap.get(depName) != null) {
				return depCodeMap.get(depName);
			} else if (hisDepCodeMap.get(depName) != null) {
				return hisDepCodeMap.get(depName);
			} else {
				return null;
			}
		}
	    
	    private String getDepName(String depName) {
	    	if (hisDepNameMap.get(depName) != null) {
				return hisDepNameMap.get(depName);
			} else if(depCodeMap.get(depName) != null){
				return depName;
			} else {
				return null;
			}
		}
	    
	    private double toDouble(Object object){
	    	
	    	if (object==null || "".equals((object+"").trim())) {
				return 0;
			} else {
				try {
					return Double.valueOf(object+"");
				} catch (Exception e) {
					return 0;
				}
				
			}
	    }
	}

}
